package org.rcgwt.client.ui.calendar.model.impl;

import java.util.List;

import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.VerticalPanel;

/**
 * An event details popup (it can be displayed when an user points an event)
 * 
 * @author Elian ORIOU
 * 
 */

public class EventDetailsPopup extends PopupPanel {

	private List<Event> events;
	private FlexTable ft;

	public EventDetailsPopup(List<Event> events, int x, int y) {
		this.events = events;
		this.render();
		this.setPopupPosition(x, y);
		this.setAnimationEnabled(true);
		this.setGlassEnabled(true);
		this.setAutoHideEnabled(true);
	}

	private void render() {
		ft = new FlexTable();
		ft.setStyleName("rcgwt-richCalendar-EventPopup");

		for (int i = 0; i < events.size(); i++) {
			Event e = events.get(i);
			VerticalPanel vp = new VerticalPanel();
			vp.setStyleName("rcgwt-richCalendar-EventPopup-events");
			if (e.getFrequency() == EventFrequency.NONE) {
				vp.add(new Label("[" + e.getTitle() + "]"));
				vp.add(new Label(e.getContent()));
				vp.add(new Label("dates : " + e.getStartTime() + " to "
						+ e.getEndTime()));
				vp.add(new Label("where : " + e.getPlace()));
			} else if (e.getFrequency() == EventFrequency.EVERYDAY) {
				vp.add(new Label("[" + e.getTitle() + "]"));
				vp.add(new Label(e.getContent()));
				vp.add(new Label("where : " + e.getPlace()));
				vp.add(new Label("Frequency : Everyday"));
			}
			ft.setWidget(i, 0, vp);
		}

		this.add(ft);
	}
}
